/** @author A0105514U */
// @author A0105514U

package global;

import java.net.HttpURLConnection;
import java.net.URL;

public class InternetConnectionDetector {
	
	public InternetConnectionDetector(){
		
	}
	
	// detect whether internet connection is established by sending a request to google homepage 
	// and evaluate the request results.
	public boolean detect(){
		try{
			URL url = new URL("http://www.google.com");
			HttpURLConnection urlConnect = (HttpURLConnection) url.openConnection();
			Object objData = urlConnect.getContent();
		}catch(Exception e){
			return false;
		}
		
		return true;
	}
	
	// Adopt Singleton design patterns here
	public static InternetConnectionDetector getDetector(){
		return new InternetConnectionDetector();
	}
}